package com.asiainfo.dacp.datastash.orm.po.his;

import com.asiainfo.dacp.jpa.annotation.ColumnPosition;
import com.asiainfo.dacp.util.DateHelper;
import lombok.Data;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name="dacp_datastash_unit_his")
public class DataStashUnitHisPo {
    @Id
    @Column(name="his_id",length = 32)
    private String id;

    @Column(name="unit_id",length = 32)
    @ColumnPosition(1)
    private String unitId;

    @Column(name="unit_code",length = 16)
    @ColumnPosition(2)
    private String unitCode;

    @Column
    @ColumnPosition(3)
    private int version;

    @Column(length = 64)
    @ColumnPosition(4)
    private String label;

    @Column(length = 128)
    @ColumnPosition(5)
    private String descr;

    @Column(name="unit_type",length = 8)
    @ColumnPosition(6)
    private String unitType;

    @Column(name="workgroup",length = 16)
    @ColumnPosition(7)
    private String workgroup;

    @Column(name="batch_type",length = 8)
    @ColumnPosition(8)
    private String batchType ;

    @Column(name="batch_step")
    @ColumnPosition(9)
    private int batchStep ;

    @Column(name="batch_offset")
    @ColumnPosition(10)
    private int batchOffset ;

    @Column(name="batch_no",length = 16)
    @ColumnPosition(11)
    private String batchNo;

    @Column(name="unit_priority")
    @ColumnPosition(12)
    private int unitPriority;

    @Column(name="member_id",length = 32)
    @ColumnPosition(13)
    private String memberId;

    @Column(name="create_user",length = 32)
    @ColumnPosition(14)
    private String createUser;

    @Column(name="create_dt")
    @ColumnPosition(15)
    private Date createDt=new Date();

    @Transient
    private String createDate;

    public String getCreateDate(){
        if(createDate==null || createDate.length()==0){
            createDate = DateHelper.formatDateTime(createDt);
        }
        return createDate;
    }

    public void setCreateDate(String createDate){
        this.createDate = createDate;
        createDt = DateHelper.parseDateTime(createDate);
    }

    @Column
    @ColumnPosition(16)
    private Date lastupd = new Date();

    @Transient
    private String lastupDate;

    public String getLastupDate(){
        if(lastupDate==null || lastupDate.length()==0){
            lastupDate = DateHelper.formatDateTime(lastupd);
        }
        return createDate;
    }

    public void setLastupDate(String lastupDate){
        this.lastupDate = lastupDate;
        lastupd = DateHelper.parseDateTime(lastupDate);
    }

    @Column(name="unit_ext_cfg",length = 1024)
    @ColumnPosition(17)
    private String unitExtCfg;

    @Column
    @Lob
    @ColumnPosition(18)
    private String graph;

    @Column(length = 8)
    @ColumnPosition(19)
    private String state;

}
